(function ($) {

    $.extend({
        echarts : {

            time : 1000,
            /**
             * 设置双轴折线图
             * @param title 标题
             * @param legend 两边Y轴名称
             * @returns
             */
            getDoubleLineOption : function (title,legend) {
                let option = {
                    title: {
                        text: title
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: legend
                    },
                    toolbox: {
                        show: true,
                        feature: {
                            dataView: {
                                readOnly: false
                            },
                            restore: {},
                            saveAsImage: {}
                        }
                    },
                    dataZoom: {
                        show: false,
                        start: 0,
                        end: 100
                    },
                    xAxis: [{
                        type: 'category',
                        boundaryGap: false,
                        data: (function() {
                            let now = new Date();
                            let res = [];
                            let len = 10;
                            while (len--) {
                                res.unshift(now.toLocaleTimeString().replace(/^\D*/, ''));
                                now = new Date(now - 2000);
                            }
                            return res;
                        })()
                    }],
                    yAxis: [{
                        type: 'value',
                        scale: true,
                        name: legend[0],
                        min:0,
                        boundaryGap: [0.2, 0.2]
                    }, {
                        type: 'value',
                        scale: true,
                        name: legend[1],
                        min: 0,
                        boundaryGap: [0.2, 0.2]
                    }],
                    series: [{
                        name: legend[0],
                        type: 'line',
                        yAxisIndex: 1,
                        data: (function() {
                            let res = [];
                            let len = 10;
                            while (len--) {
                                res.push(0);
                            }
                            return res;
                        })()
                    }, {
                        name: legend[1],
                        type: 'line',
                        data: (function() {
                            let res = [];
                            let len = 0;
                            while (len < 10) {
                                res.push(0);
                                len++;
                            }
                            return res;
                        })()
                    }]
                };

                return option;
            },
            /**
             *  设置动态数据
             * @param option
             * @param axisData
             * @param data_1
             * @param data_2
             */
            setDynamicData: function(option,axisData,data_1,data_2){

                let data0 = option.series[0].data;
                let data1 = option.series[1].data;

                //设置显示数据
                data0.shift();
                data0.push(data_1);
                data1.shift();
                data1.push(data_2);
                //设置X轴
                option.xAxis[0].data.shift();
                option.xAxis[0].data.push(axisData);

                return option;
            },
            /**
             * 设置定时器
             * @param fn
             * @param time
             * @returns {number}
             */
            setChartInterval : function (fn,time) {
                let t = setInterval(fn,time);
                return t;
            }

        }

    });
})(jQuery);